package com.yao.component.circle;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;


import com.yao.component.circle.dataobject.CircleProfile;
import com.yao.component.circle.dataobject.Post;
import com.yao.component.pictureselector.PictureSelector;
import com.yao.sdk.net.ResponseInfo;
import com.yao.sdk.ui.UIActivity;
import com.hzl.PictureDialog;
import com.yzf.PublishActivity;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2015/10/29.
 */
public class CircleActivity extends UIActivity {

    CircleView circleView;
    private PictureDialog pay;
    TestData testData;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_circle);
        CircleProfile.getInstance().setUserId(1 + "");
        CircleProfile.getInstance().setField1(2 + "");
        CircleProfile.getInstance().setName("Jack");
//        CircleProfile.getInstance().setUserIcon(R.drawable.icon0001);
        circleView = (CircleView) findViewById(R.id.circle_list);
        CircleController.getInstance().getTestData().setCircleView(circleView);
        circleView.setDataSource(CircleController.getInstance().getTestData());
        Log.d("test", "main--->");
        pay = new PictureDialog(this, new PictureDialog.onPictureDialogListener() {
            @Override
            public void onCamare() {

            }

            @Override
            public void onAlbum() {
                PictureSelector pictureSelector = new PictureSelector(CircleActivity.this, new PictureSelector.onPictureSelectListener() {
                    @Override
                    public void onSelect(List<String> selectPath) {
                        Intent intent=new Intent(CircleActivity.this, PublishActivity.class);
                        intent.putStringArrayListExtra("picture_list",(ArrayList<String>) selectPath);
                        CircleActivity.this.startActivityForResult(intent, Constant.REQUEST_CODE_POST);
                    }

                    @Override
                    public void onCancel() {


                    }
                });
                pictureSelector.show();
            }

            @Override
            public void onCancle() {
            }
        });
        BaseTopViewUtil.setRightImg(this, R.drawable.camera, new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                pay.show();
            }
        });

        BaseTopViewUtil.setLeftImg(this, R.drawable.back, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                CircleActivity.this.finish();
            }
        });
        BaseTopViewUtil.setTitleText(this, "朋友圈");
        //if(MyApp.organizationId!=0){
           // circleView = (CircleView) findViewById(R.id.circle_list);
            //circleView.getDefaultCircleDataSource().setCircleView(circleView);
           // circleView.setDataSource(circleView.getDefaultCircleDataSource());
       /* circleView.getCircleStyle().setItemNameTextColor(R.color.title_bg).setCommentItemNameTextColor(R.color.title_bg)
                .setItemContentOptTextColor(R.color.title_bg);*/
    /*    circleView.setDataSource(new DefaultDataSource());
        circleView.refresh();*/
     //   showDialog(null);
       // circleView.requestPost();
       // }

    }



    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        Log.d("test", "onActivityResult-resultCode-->" + resultCode);
        if (resultCode == Constant.REQUEST_CODE_POST) {// selected image
           // circleView.requestPost();
            if (data != null) {
                Post post = (Post)data.getSerializableExtra(PublishActivity.KEY_POST);
                if (post != null) {
                    CircleController.getInstance().getTestData().getCachedPost().add(post);
                    circleView.refresh();
                }
            }
        }
    }

    @Override
    public void onResponse(String url, ResponseInfo responseInfo) {
        super.onResponse(url, responseInfo);

        Log.d("test", "CircleActivity-->" +  url);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        CircleController.getInstance().getTestData().setCircleView(null);
    }
}
